package com.monster.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.monster.entity.PageResult;
import com.monster.entity.QueryPageBean;
import com.monster.mapper.CheckItemMapper;
import com.monster.pojo.CheckItem;
import com.monster.pojo.User;
import com.monster.service.CheckItemService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {



    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Page<CheckItem> page;
        QueryWrapper<CheckItem> checkItemQueryWrapper = new QueryWrapper<>();
        //逻辑删除
        checkItemQueryWrapper.eq("IS_DELETE",0);
        if(queryPageBean.getQueryString() != null){
            //有条件查询
            checkItemQueryWrapper.like("name",queryPageBean.getQueryString());
            page =  page(new Page<CheckItem>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()),checkItemQueryWrapper);
        }else{
            // 无条件分页
            page = page(new Page<CheckItem>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()),checkItemQueryWrapper);
        }
        PageResult result = new PageResult(page.getTotal(),page.getRecords());
        return result;
    }

    @Override
    public List<CheckItem> findRecoverPage(QueryPageBean queryPageBean) {
        QueryWrapper<CheckItem> checkItemQueryWrapper = new QueryWrapper<>();
        // 历史恢复查询
        checkItemQueryWrapper.eq("IS_DELETE",1);
        List<CheckItem> list = this.list(checkItemQueryWrapper);
        return list;
    }

    //逻辑删除
    @Override
    public Boolean deleteCheckitemById(int id) {
        CheckItem checkItem = new CheckItem();
        checkItem.setId(id);
        checkItem.setIs_delete(1);
        boolean b = this.updateById(checkItem);
        return b;
    }
    //删除恢复
    @Override
    public Boolean recoverCheckItemById(int id) {
        CheckItem checkItem = new CheckItem();
        checkItem.setId(id);
        checkItem.setIs_delete(0);
        boolean b = this.updateById(checkItem);
        return b;
    }

    @Override
    public List<CheckItem> findAll() {
        return this.list();
    }
}
